/*
 * Copyright (c) 2012 Tyler Treat
 * 
 * This file is part of Infinitum Framework.
 *
 * Infinitum Framework is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Infinitum Framework is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Infinitum Framework.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.clarionmedia.infinitum.http.rest.impl;

import com.clarionmedia.infinitum.http.rest.MessageConverter;
import com.google.gson.Gson;

/**
 * <p>
 * Implementation of {@link MessageConverter} which relies on Gson to perform
 * object conversions.
 * </p>
 * 
 * @author Tyler Treat
 * @version 1.0 12/23/12
 * @since 1.0
 */
public class GsonMessageConverter implements MessageConverter {

	private Gson mGson;

	public GsonMessageConverter() {
		mGson = new Gson();
	}

	public GsonMessageConverter(Gson gson) {
		mGson = gson;
	}

	@Override
	public <T> T convert(Class<T> clazz, RestResponse response) {
		return mGson.fromJson(response.getResponseDataAsString(), clazz);
	}

}
